import 'package:flutter/material.dart';
import 'package:untitleqianru/test.dart';

import 'DBProvider.dart';

DaoCase daoCase = new DaoCase();

void main() {
  runApp(InitSql());
}

class InitSql extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {

    daoCase.sqlInit2().then((data) {
      print('%数据库初始化结束');
      daoCase.isTableExits().then((data) {
        if (data) {
          runApp(MyApp());
        } else {
          daoCase.creaatTable().then((data) {
            print('%数据库初始化结束2');
            daoCase.isTableExits().then((data) {
              if (data) {
                runApp(MyApp());
              } else {
                print('daoCaseERROR2222');
              }
              print(data);
            }).catchError((err) {
              print('%daoCase失败222');
              print(err);
            });
          }).catchError((err) {
            print('%数据库初始化失败222');
            print(err);
          });
        }
        print(data);
      }).catchError((err) {
        print('%daoCase失败111');
        print(err);
      });
    }).catchError((err) {
      print('%数据库初始化失败1111');
      print(err);
    });

    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Builder(
        builder: (context) {
          // 这里使用builder回调获取Builder本身的context
          return Scaffold(
            appBar: AppBar(title: const Text('Navigator跳转页面')),
            body: Center(
              child: GestureDetector(
                child: const Text('数据库初始化ing', textDirection: TextDirection.ltr),
              ),
            ),
          );
        },
      ),
    );
  }
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}


